#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
    long long sum = 0;
    long long sum1 = 0;
    int n;
    cin >> n;
    string ret;
    cin >> ret;
    int hnum = 0, ynum = 0;
    for (int i = n-1; i >= 0; i--)
    {
        if (ret[i] == 'h') hnum++;
        else if (ret[i] == 'y')
        {
            sum1 += hnum * ynum;
            hnum = 0;
            ynum++;
        }
        else if (ret[i] == 's')
        {
            sum += hnum * ynum + sum1;
        }
    }
    cout << sum;
    return 0;
}